#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
#include <string.h>

#define JUMP_CMD 3

static jmp_buf jmpb;

void testc(const char * buf);
void readc(char * const buf);

int main(int argc, char *argv[]) {
    char buffer[4096];
    volatile int testval = 1;
    switch (setjmp(jmpb)) {
        case 0:
            break;
        case JUMP_CMD:
            printf("again! (testval: %d)\n", testval);
            break;
        }
    testval = 100;
    readc(buffer);
    testc(buffer);
    printf("ok -> %s", buffer);
    return EXIT_SUCCESS;
}

void readc(char * const buf) {
    printf("enter: ");
    if (fgets(buf, 4096, stdin) == NULL) {
        printf("Error fgets\n");
        exit(EXIT_FAILURE);
    }
}

void testc(const char * buf) {
    if (strcmp(buf, "jump\n") == 0){
        longjmp(jmpb, JUMP_CMD);
    }
}
